package com.ikangtai.shecare.stickycalendar.init;

import android.content.Context;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.App;
import com.ikangtai.shecare.common.al.DayUnitDSOutput;
import com.ikangtai.shecare.common.db.DBManager;
import com.ikangtai.shecare.common.util.AppLog;
import com.ikangtai.shecare.common.util.DateUtil;
import com.ikangtai.shecare.record.bean.UserRecordData;
import com.ikangtai.shecare.record.bean.UserTemperatureInfo;
import com.ikangtai.shecare.stickycalendar.http.util.BBTMsg;

import org.simple.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ikangtai on 2016/9/8.
 */
public class InitRecordMenses {

    private Context context;
    private static DBManager dbManager;
    private String dateRecord; // 具体某天的时间

    public InitRecordMenses(Context context, String dateRecord){
        this.context = context;
        dbManager = new DBManager(context);
        EventBus.getDefault().register(this);
        this.dateRecord = dateRecord;
    }

    /**
     * 进入记录界面 初始化部分
     */
    public void setCurrentRecordMensesType(){

        long currentRecordTime = DateUtil.getStringToDate(dateRecord + " 12:00:00");
        List<DayUnitDSOutput> dayOutputList = new ArrayList<>();
        boolean isHaveStartMenses = false;
        for(int i =  14; i >= 0; i--){
            if(null != App.DayUnitDSOutputMap.get(currentRecordTime - i * (24 * 3600))){
                dayOutputList.add(App.DayUnitDSOutputMap.get(currentRecordTime - i * (24 * 3600)));

                if(App.DayUnitDSOutputMap.get(currentRecordTime - i * (24 * 3600)).homePageNextMenstruation == 1)
                    isHaveStartMenses = true;
            }
        }

        if(dayOutputList.size() >= 10){
            if(isHaveStartMenses){
                if(dayOutputList.get(dayOutputList.size() - 2).homePageNextMenstruation == 1){
                    if(App.DayUnitDSOutputMap.get(currentRecordTime).periodAchieveConfirm >0){
//                        recordMensesYesBtn.clickAction(mensesView);
//                        mensesHint.setText(getString(R.string.record_menses_measure_hint));
//                        mensesHintValue = 1;
//                        mensesChoiceValue = 1;
//                        referMensesChoiceValue = 1;
//                        mensesBlood = 1;
                        AppLog.i("wzz----init----姨妈来了 1 1 1");
                    }else{
//                        recordMensesNoBtn.clickAction(mensesView);
//                        mensesHint.setText(getString(R.string.record_menses_measure_hint));
//                        mensesHintValue = 1;
//                        mensesChoiceValue = 0;
//                        referMensesChoiceValue = 0;
                        AppLog.i("wzz----init----姨妈来了 1 0 0");
                    }
                    return;
                }

                if(App.DayUnitDSOutputMap.get(currentRecordTime).homePageNextMenstruation == 1){
//                    recordMensesNoBtn.clickAction(mensesView);
//                    mensesHint.setText(getString(R.string.record_menses_measure_hint));
//                    mensesHintValue = 1;
//                    mensesChoiceValue = 0;
//                    referMensesChoiceValue = 0;
                    AppLog.i("wzz----init----姨妈来了 1 0 0");
                }else{
                    boolean haveConfirmPS = false;
                    for(DayUnitDSOutput dayUnitDSOutput : dayOutputList){
                        if(dayUnitDSOutput.periodAchieveConfirm > 0){
                            haveConfirmPS = true;
                            break;
                        }
                    }
                    AppLog.e("haveConfirmPS:" + haveConfirmPS);
                    if(haveConfirmPS == false){
//                        recordMensesNoBtn.clickAction(mensesView);
//                        mensesHint.setText(getString(R.string.record_menses_measure_hint));
//                        mensesHintValue = 1;
//                        mensesChoiceValue = 0;
//                        referMensesChoiceValue = 0;
                        AppLog.i("wzz----init----姨妈来了 1 0 0");
                    }else{
                        if(App.DayUnitDSOutputMap.get(currentRecordTime).homePageMenstruationEnd == 0){
//                            recordMensesYesBtn.clickAction(mensesView);
//                            mensesHint.setText(getString(R.string.record_menses_measure_hint_no));
//                            mensesHintValue = 0;
//                            mensesChoiceValue = 1;
//                            referMensesChoiceValue = 1;
                            AppLog.e("mensesHint 0 1 1");
                            AppLog.i("wzz----init----姨妈走了 0 1 1");
                        }else {
//                            recordMensesNoBtn.clickAction(mensesView);
//                            mensesHint.setText(getString(R.string.record_menses_measure_hint_no));
//                            mensesHintValue = 0;
//                            mensesChoiceValue = 0;
//                            referMensesChoiceValue = 0;
                            AppLog.i("wzz----init----姨妈走了 0 0 0");
                        }

                        if(App.DayUnitDSOutputMap.get(currentRecordTime).periodAchieveForecast >0){
                            //设置确认的经期
                            //mensesBlood = 1;
                        }
                    }

                }

            }else{
//                recordMensesNoBtn.clickAction(mensesView);
//                mensesHint.setText(getString(R.string.record_menses_measure_hint));
//                mensesHintValue = 1;
//                mensesChoiceValue = 0;
//                referMensesChoiceValue = 0;
                AppLog.i("wzz----init----姨妈来了 1 0 0");
            }

        }else{
//            recordMensesNoBtn.clickAction(mensesView);
//            mensesHint.setText(getString(R.string.record_menses_measure_hint));
//            mensesHintValue = 1;
//            mensesChoiceValue = 0;
//            referMensesChoiceValue = 0;
            AppLog.i("wzz----init----姨妈来了 1 0 0");
        }

    }
}
